package com.yonyou.cyxdms.sysAuth.service.controller.manage.position;

import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;
import com.yonyou.cyxdms.sysAuth.service.service.position.PositionService;
import com.yonyou.cyxdms.sysmanage.client.vo.user.UserInfoVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author ：quankk
 * @date ：2019/7/11 15:33
 * @description：
 */
@RestController
@RequestMapping("/basedata/positions")
public class PositionController extends BaseController {
    // 定义日志接口
    private static final Logger logger = LoggerFactory.getLogger(PositionController.class);

    @Autowired
    private PositionService positionService;


    @ApiOperation(value = "查询职务（下拉框）")
    @ApiImplicitParams({@ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")})
    @RequestMapping(value = "/duty/dicts", method = RequestMethod.GET)
    public List<Map<String, Object>> findAllPosition() {
        return positionService.findAllPosition();
    }

    /**
     * 查询用户职位
     * 李贺
     */
    @ApiOperation(value = "查询用户职位")
    @ApiImplicitParams({@ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")})
    @GetMapping(value = "/getPositions")
    public List<Integer> getPositions(@RequestParam(value = "userId", required = false) Long userId) {
        if (userId == null) {
            LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
            userId = loginInfoDto.getUserId();
        }
        return positionService.getPositions(userId);
    }

    /**
     * 根据orgId获得所有的人员信息
     *
     * @author 李贺
     * @since 2019/11/19
     */
    @GetMapping("/getUserByOrgId")
    @ApiOperation(value = "根据orgId获得所有的人员信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    public List<UserInfoVO> getUserByOrgId(@RequestParam(value = "orgId") String orgId) {
        return positionService.getUserByOrgId(orgId);
    }
}
